<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var Data = new Date();

        console.log(Data);

        let year = Data.getFullYear();
        let mon = Data.getMonth()+1;
        let day = Data.getDate();

        console.log(year);
        console.log(mon);
        console.log(day);

        // padStart

        // 变成字符串 的数字
        let strMon = mon.toString();
    
        // console.log(strMon.padStart(2,'0'));
        // 补零之后的字符串
        let add0Mon = strMon.padStart(2,'0');

        let str = `${year}-${add0Mon}-${day}`;

        console.log(str);

        // 2023-02-27 08:36:05


        // 封装函数
        function add0Fn(num){
            let str = num.toString();

           return str.padStart(2,'0');
        }


        console.log(add0Fn(1));
    </script>
    
</body>
</html>